package com.franklin.java.service.database;

import com.franklin.java.entity.CostTime;
import com.franklin.java.entity.sql.JdbcInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.util.Key;

import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * 所有方法的第一个参数皆为JdbcInfo
 * @author Franklin
 * @since 2021/9/25 10:12
 */
public interface JdbcService {

    static JdbcService getInstance(){
        return JdbcServiceImpl.instance;
    }

    /**
     * 添加数据源<br>
     * @author Franklin
     * @since 2021/9/25 10:13
     * @param jdbcInfo
     * @return boolean
     */
    boolean addDataSource(JdbcInfo jdbcInfo);

    /**
     * 获取连接<br>
     * @author Franklin
     * @since 2021/9/25 10:13
     * @param jdbcInfo
     * @return java.sql.Connection
     */
    Connection getConnection(JdbcInfo jdbcInfo) throws SQLException;

    /**
     * <br>
     * @author Franklin
     * @since 2021/9/25 10:49
     * @param jdbcInfo :
     * @param sql :
     * @param resultSetConsumer :
     * @return void
     */
    CostTime executeQuery(JdbcInfo jdbcInfo, String sql, BiConsumer<ResultSet,CostTime> resultSetConsumer) throws SQLException;
}
